package itsm.isperp.framework.data.dialect.impl;

import itsm.isperp.framework.data.dialect.Dialect;

/**
 * Mysql方言的实现
 * 
 */
public class OracleDialect implements Dialect {

	public boolean supportsLimit() {
		return true;
	}

	@Override
	public String getLimitString(final String sql, int offset, int limit) {

		StringBuilder pagingSelect = new StringBuilder();

		pagingSelect.append(
				"SELECT * FROM ( SELECT row_.*, rownum AS rownum_ FROM ( ")
				.append(sql);
		pagingSelect.append(" ) row_  where rownum<=" +(offset + limit)+ ")t WHERE  rownum_ > " + offset);

		return pagingSelect.toString();
	} 

	@Override
	public String getLimitString(final String sql) {

		StringBuilder pagingSelect = new StringBuilder();

		pagingSelect.append("SELECT * FROM (").append(sql);

		pagingSelect.append(" )t WHERE  rownum=1 ");

		return pagingSelect.toString();
	}

	@Override
	public String getLimitString(int offset, int limit) {
		return " AND  rownum =1 ";
	}

}
